<?php

namespace common\models\dynamic;

use Yii;
use common\helpers\Url;

/**
 * This is the model class for table "{{%dynamic_gallery}}".
 *
 * @property int $id
 * @property int $dynamic_id 动态ID
 * @property string $thumb 缩略图
 * @property string $original 图片地址
 * @property int $format 格式：0图片，1视频
 * @property int $listorder 显示排序
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class DynamicGallery extends \common\base\ActiveRecord {

    use \common\traits\TimestampBehavior;
    use \common\traits\QueryInstanceActiveRecord;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%dynamic_gallery}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['dynamic_id', 'format', 'listorder', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['thumb', 'original'], 'required'],
            [['thumb', 'original'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'dynamic_id' => '动态ID',
            'thumb' => '缩略图',
            'original' => '图片地址',
            'format' => '格式：0图片，1视频',
            'listorder' => '显示排序',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    public function getPicture() {
        return Url::toRemote($this->original);
    }

    public function getThumbnail() {
        return Url::toRemote($this->thumb);
    }

}
